package com.chinamobile.iot.config;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

/**
 * Created on 2016/12/26.
 *
 * @author szl
 */
@Configuration
@ConfigurationProperties(prefix = "mqtt")
public class MqttConfiguration {

    public final static String WORK_MODE_STANDALONE = "standalone";
    public final static String WORK_MODE_DISTRIBUTE = "distribute";

    /**
     * the auth server that support rest api for auth
     */
    private String authAddress;
    /**
     * the timeout second between tcp third handshake and the mqtt Connect message
     */
    private int connectTimeout;
    /**
     * the time out second between the command mqtt publish and the mqtt pub ack. command uses QoS1
     */
    private int cmdTimeout;

    /**
     * if this mqtt broker enable the cleanSession flag and the logic
     */
    private boolean cleanSession;
    /**
     * the listening host of mqtt server
     */
    private String host;
    /**
     * the listen port of the mqtt server
     */
    private int port;
    /**
     * the ssl configuration
     */
    private SSL ssl;
    /**
     * if the broker is enable subscribe message. if it is false, then if this broker receive subscripe message,
     * is will disconnect the client.
     */
    private boolean subscribe;
    /**
     * enable kafka of not, if enable, broker will save data to kafka, otherwise it will just check is some one subscribe the data
      */
    private boolean kafka;
    /**
     * enable distribute of not. if enable, it enable zookeeper and redis and can be use at distribute enviroment
     */
    private boolean distribute;

    /**
     * if this broker allow anonymous login
     */
    private boolean anonymous;
    /**
     * if this broker send welcome message to the client when it is first successfully login.
     */
    private boolean sendWelcome;
    /**
     * the max client this broker allow to connect. if the client count reach the maxClient, the broker will refuse new client login
     */
    private int maxClient;

    public String getAuthAddress() {
        return authAddress;
    }

    public void setAuthAddress(String authAddress) {
        this.authAddress = authAddress;
    }

    public int getConnectTimeout() {
        return connectTimeout;
    }

    public void setConnectTimeout(int connectTimeout) {
        this.connectTimeout = connectTimeout;
    }

    public int getCmdTimeout() {
        return cmdTimeout;
    }

    public void setCmdTimeout(int cmdTimeout) {
        this.cmdTimeout = cmdTimeout;
    }

    public boolean isCleanSession() {
        return cleanSession;
    }

    public void setCleanSession(boolean cleanSession) {
        this.cleanSession = cleanSession;
    }

    public String getHost() {
        return host;
    }

    public void setHost(String host) {
        this.host = host;
    }

    public int getPort() {
        return port;
    }

    public void setPort(int port) {
        this.port = port;
    }

    public SSL getSsl() {
        return ssl;
    }

    public void setSsl(SSL ssl) {
        this.ssl = ssl;
    }

    public boolean isSubscribe() {
        return subscribe;
    }

    public void setSubscribe(boolean subscribe) {
        this.subscribe = subscribe;
    }

    public boolean isKafka() {
        return kafka;
    }

    public void setKafka(boolean kafka) {
        this.kafka = kafka;
    }

    public boolean isDistribute() {
        return distribute;
    }

    public void setDistribute(boolean distribute) {
        this.distribute = distribute;
    }

    public boolean isAnonymous() {
        return anonymous;
    }

    public void setAnonymous(boolean anonymous) {
        this.anonymous = anonymous;
    }

    public boolean isSendWelcome() {
        return sendWelcome;
    }

    public void setSendWelcome(boolean sendWelcome) {
        this.sendWelcome = sendWelcome;
    }

    public int getMaxClient() {
        return maxClient;
    }

    public void setMaxClient(int maxClient) {
        this.maxClient = maxClient;
    }

    public static class SSL {

        private int port;
        private int period;
        private String jks;
        private String cer;
        private String password;

        public int getPort() {
            return port;
        }

        public void setPort(int port) {
            this.port = port;
        }

        public String getJks() {
            return jks;
        }

        public void setJks(String jks) {
            this.jks = jks;
        }

        public String getCer() {
            return cer;
        }

        public void setCer(String cer) {
            this.cer = cer;
        }

        public int getPeriod() {
            return period;
        }

        public void setPeriod(int period) {
            this.period = period;
        }

        public String getPassword() {
            return password;
        }

        public void setPassword(String password) {
            this.password = password;
        }
    }
}
